package com.cn.web.controller.PartsManagement;

import com.alibaba.fastjson2.JSONObject;
import com.cn.bean.pojo.lbj.ComponentCategory;
import com.cn.config.config.Result;
import com.cn.service.server.PartsManagement.ComponentCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@Slf4j
@Transactional
public class ComponentCategoryController {
    @Autowired
    private ComponentCategoryService categoryService;
    @RequestMapping("/select/ComponentMechanicalUsageCategory")
    @ResponseBody
    public List<ComponentCategory> selectComponentMechanicalUsageCategory(@RequestBody ComponentCategory category) {

        List<ComponentCategory> businessTypeTables = categoryService.selectComponentMechanicalUsageCategory(category);
        return businessTypeTables;
    }

    @RequestMapping("/add/ComponentMechanicalUsageCategory")
    @ResponseBody
    public Result addComponentMechanicalUsageCategory(@RequestBody JSONObject jsonObject) {
        ComponentCategory formAsid = jsonObject.getObject("formAsid", ComponentCategory.class);

        Result result = categoryService.addComponentMechanicalUsageCategory(formAsid.getName(), formAsid.getDescription(), formAsid.getStatus());
//        return businessTypeService.addBusinessType();
        return result;
    }
    //
    @RequestMapping("/delete/ComponentMechanicalUsageCategory")
    @ResponseBody
    public Result deleteComponentMechanicalUsageCategory(@RequestBody JSONObject jsonObject) {
        ComponentCategory asid=new ComponentCategory();
        asid = jsonObject.getObject("formAsid", ComponentCategory.class);
//        if (asid.getId()==0||asid.getId()==1){
//            return Result.failure("业务类型字段不可修改");
//        }
        int id = asid.getId();
        return categoryService.delComponentMechanicalUsageCategoryStatus(id);
    }

    @RequestMapping("/update/ComponentMechanicalUsageCategory")
    @ResponseBody
    public Result updateComponentMechanicalUsageCategory(@RequestBody JSONObject jsonObject) {
        ComponentCategory formAsid = jsonObject.getObject("formAsid", ComponentCategory.class);
//        if (formAsid.getId()==0||formAsid.getId()==1){
//            return Result.failure("业务类型字段不可删除");
//        }
        Result result = categoryService.updateComponentMechanicalUsageCategory(formAsid.getId(), formAsid.getCode(), formAsid.getName(), formAsid.getDescription(), formAsid.getStatus());
        return result;
    }
    @RequestMapping("/select/ComponentMechanicalUsageCategory/AllAuyo1")
    @ResponseBody
    public List<ComponentCategory> selectAllAuyo1(@RequestBody ComponentCategory category) {

        List<ComponentCategory> businessTypeTables = categoryService.selectAllAuyo1();
        return businessTypeTables;
    }
}

